package com.yanqu.road.server.cmd.activity.liondance;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LionDanceProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.liondance.LionDanceModule;
import com.yanqu.road.server.manger.activity.liondance.LionDanceMakeProcess;
import com.yanqu.road.server.manger.activity.liondance.LionDanceMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_LION_DANCE_ALL_CONTRIBUTION_SYNC_FROM_CROSS, desc = "全服进度同步")
public class LionDanceSyncAllMakeNumFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        LionDanceProto.CrossLionDanceSyncAllMakeNumMsg sync = LionDanceProto.CrossLionDanceSyncAllMakeNumMsg.parseFrom(yanQuMessage.getBytes());

        //缓存
        LionDanceMgr.getCacheAllMakeNumMap().put(sync.getActivityId(), new LionDanceMakeProcess(sync.getCount(), sync.getProcess()));

        for (GamePlayer player : GamePlayerMgr.getCopyPlayerList()) {
            player.getModule(LionDanceModule.class).updateAllMakeNum(sync.getActivityId(), sync.getCount(), sync.getProcess());
        }
    }
}
